<?php echo $header; ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>

<div id="dialog" title="Confirm" style="display: none;">
    <p>Delete cannot be undone! Are you sure you want to do this?</p>
</div>
<div id="dialog1" title="Confirm" style="display: none;">
    <p>Please select an item to delete.</p>
</div>

<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('view/image/category.png');"><?php echo $heading_title; ?></h1>
    <div class="buttons">
        <a onclick="location = '<?php echo $insert; ?>'" class="button"><span><?php echo $button_insert; ?></span></a>
        <a onclick="$('#form').submit();" class="button"><span><?php echo $button_delete; ?></span></a>        
    </div>
  </div>
  <div class="content">
    <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
      <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
            <td class="left"><?php echo $column_name; ?></td>
            <td class="right"><?php echo $column_sort_order; ?></td>
            <td class="right"><?php echo $column_action; ?></td>
          </tr>
        </thead>
        <tbody>
          <?php if ($categories) { ?>
          <?php foreach ($categories as $category) { ?>
          <tr>
            <td style="text-align: center;"><?php if ($category['selected']) { ?>
              <input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
              <?php } else { ?>
              <input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" />
              <?php } ?></td>
            <td class="left"><?php echo $category['name']; ?></td>
            <td class="right"><?php echo $category['sort_order']; ?></td>
            <td class="right"><?php foreach ($category['action'] as $action) { ?>
              [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
              <?php } ?></td>
          </tr>
          <?php } ?>
          <?php } else { ?>
          <tr>
            <td class="center" colspan="4"><?php echo $text_no_results; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
    </form>
  </div>
</div>

<link type="text/css" rel="stylesheet" href="view/javascript/jquery/ui/themes/smoothness/ui.all.css" />
<script type="text/javascript" src="view/javascript/jquery/ui/ui.dialog.js"></script>

<script type="text/javascript"><!--    
    jQuery(document).ready(function(){ 
        jQuery('#dialog').dialog({
            autoOpen: false,
            width: 300,
            modal: true,
            resizable: false,
            buttons: {
                "Cancel": function() { 
                    jQuery(this).dialog("close"); 
                },
                "Ok": function() { 
                    jQuery('#form_category').submit();
                }
            }
        }); 
        jQuery('#dialog1').dialog({
            autoOpen: false,
            width: 300,
            modal: true,
            resizable: false,
            buttons: {
                "Close": function() { 
                    jQuery(this).dialog("close"); 
                }
            }
        });   
        
        jQuery('#form_category').submit(function(even){   
            even.preventDefault();
            
            var checked = 0;
            jQuery('#form_category input[name="selected[]"]').each(function(){
                if(jQuery(this).is(':checked')){                    
                    checked++;
                }
            });
            
            if(checked == 0){
                jQuery('#dialog1').dialog('open');
                return false;    
            }
            else{
                jQuery('#dialog').dialog('open');    
                return false;
            }
        })        
    });     
//-->
</script>

<?php echo $footer; ?>